package com.lzyjkz.quick_system.security;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.lzyjkz.quick_system.entity.SysUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;

@AllArgsConstructor
@Data
public class SysUserDetails implements UserDetails {

    private SysUser user;

    @Override
    @JsonIgnore
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    @JsonIgnore
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    @JsonIgnore
    public String getUsername() {
        return user.getUsername();
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonExpired() {
        return user.getStatus().getValue() == 0;
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonLocked() {
        return user.getStatus().getValue() == 0;
    }

    @Override
    @JsonIgnore
    public boolean isCredentialsNonExpired() {
        return user.getStatus().getValue() == 0;
    }

    @Override
    @JsonIgnore
    public boolean isEnabled() {
        return user.getStatus().getValue() == 0;
    }
}
